package com.example.springbootlearn.service.order;

import cn.hutool.core.lang.Console;
import cn.hutool.core.util.RandomUtil;
import com.example.springbootlearn.annotation.TestOrder;
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author libo
 * @Date 2023/5/6 22:37
 */


@Builder
@Data
@TestOrder(100)
//@Service
public class FirstChatHandle {

    private Integer id;
    private String name;
    private Integer age;

    public static void main(String[] args) {

        List<FirstChatHandle> chatHandlers = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            FirstChatHandle build = FirstChatHandle.builder()
                    .id(RandomUtil.randomInt(3)).name("afei").age(RandomUtil.randomInt(20)).build();
            chatHandlers.add(build);
        }

        Map<Integer, FirstChatHandle> map = new LinkedHashMap<>();
        for (FirstChatHandle handler : chatHandlers) {
            FirstChatHandle firstChatHandle = map.computeIfAbsent(handler.getId(), x -> handler);
            System.out.println(firstChatHandle);
//            FirstChatHandle firstChatHandle = map.compute(handler.getId(), x -> handler);
        }

        Console.log(map);

    }
}
